package com.itcam.file.config;

import com.itcam.file.service.FileStorageService;
import io.minio.MinioClient;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author : Cammy.Wu
 * Description : MinIO配置类
 */

@Data
@Configuration
@EnableConfigurationProperties({MinIOConfigProperties.class}) // 文件上传 配置前缀file.oss
@ConditionalOnClass(FileStorageService.class) // 当引入FileStorageService接口时，才加载该类
public class MinIOConfig {

    @Autowired
    private MinIOConfigProperties minIOConfigProperties;

    @Bean
    public MinioClient buildMinIOClient() {
        return MinioClient
                .builder()
                .credentials(minIOConfigProperties.getAccessKey(), minIOConfigProperties.getSecretKey())
                .endpoint(minIOConfigProperties.getEndpoint())
                .build();
    }
}
